﻿@{
    ViewBag.Title = "帮扶培训情况一览";
}
@section headerSection{
    <style>
        #exampleToolbar div {
            margin-bottom: 0px;
        }

        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-right: 5px;
            margin-top: 1px;
        }

        .form-group > button {
            margin-top: -2px;
            margin-bottom: 2px;
        }
    </style>
}
<div class="wrapper animated fadeInRight autoHeight">
    <!-- Panel Other -->
    <div class="row autoHeight" style="background-color: #fff;">
        <div class="col-sm-12 col-sm-leftRight" style="margin-top: 2px;">
            <!-- Example Toolbar -->
            <div class="example">
                <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                    <button id="trainAdd" type="button" class="btn btn-outline btn-primary">
                        <i class="glyphicon glyphicon-plus" aria-hidden="true">添加</i>
                    </button>
                    <button id="trainEdit" type="button" class="btn btn-outline btn-primary">
                        <i class="glyphicon glyphicon-pencil" aria-hidden="true">编辑</i>
                    </button>
                    <button id="trainDel" type="button" class="btn btn-outline btn-danger">
                        <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                    </button>
                </div>
                <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
            </div>
            <!-- End Example Toolbar -->
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<!-- 添加/编辑 -->
<div id="org_form" style="width: 500px; height:100%; overflow-x: hidden; display: none;">
    <form class="form-horizontal m-t" id="orgFormTable" method="post" enctype="multipart/form-data">
        <div class="form-group">
            <label class="col-sm-4 control-label">培训时间<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-7">
                <input id="help_date" name="help_date" type="text" class="form-control input-sm" required="" aria-required="true" placeholder="请选择培训时间" title="请选择培训时间" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})" />
                <input type="hidden" id="help_id" name="help_id" />
                <input type="hidden" id="user_id" name="user_id" />
                <input type="hidden" id="user_name" name="user_name" />
                <input type="hidden" id="user_identify" name="user_identify" />
            </div>  
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">培训地点<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-7">
                <input id="help_addr" name="help_addr" type="text" class="form-control input-sm" required="" aria-required="true" placeholder="请输入培训地点" title="请输入培训地点" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">培训内容：</label>
            <div class="col-sm-7">
                <textarea class="form-control" id="help_content" name="help_content" rows="4" placeholder="请输入培训内容" title="请输入培训内容"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">备注：</label>
            <div class="col-sm-7">
                <textarea class="form-control" id="com_note" name="com_note" rows="4" placeholder="请输入备注" title="请输入备注"></textarea>
            </div>
        </div>
    </form>
</div>
@section footSection{
    <script>
        $(function () {
            //初始化Page
            helpTrainManager.initPage();
        });
        var $table, addOrEditUrl, options,
                user_id, user_name,user_identify;
        var isFrish = false;//默认关闭页面时不刷新
        var helpTrainManager = {
            //初始化页面
            initPage: function () {
                parent.showLoadBoxs();
                if (!helpTrainManager.initData()) {
                    layer.msg("参数异常！");
                    return false;
                }
                helpTrainManager.initTable();
                helpTrainManager.bindEvent();
                parent.delLoadBoxs();
            },
            //初始化参数
            initData: function () {
                user_id = $.getUrls("user_id");
                if (!user_id)
                    return false;
                $('#user_id').val(user_id);
                user_name = decodeURI($.getUrls("user_name"));
                $('#user_name').val(user_name);
                user_identify = decodeURI($.getUrls("user_identify"));
                $('#user_identify').val(user_identify);
                return true;
            },
            //初始化Table
            initTable: function () {
                options = {
                    url: ctx + "/BaneJobIssue/GetSingleBaneTrainData",
                    cutHeight: 5,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            rows: params.limit,
                            //页面大小  
                            page: params.offset / params.limit + 1,
                            user_id: user_id
                        }
                        return params;
                    },
                    columns: [
                    {
                        radio: true
                    },
                    {
                        field: '',//第一列序号
                        title: '序号',
                        align: 'center',
                        width: 50,
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        field: 'user_name',
                        title: '用户名',
                        align: 'center'
                    },
                    {
                        field: 'user_identify',
                        title: '身份证',
                        align: 'center'
                    },
                    {
                        field: 'help_addr',
                        title: '培训地点',
                        align: 'center'
                    },
                    {
                        field: 'help_date',
                        title: '培训时间',
                        align: 'center'
                    },
                    {
                        field: 'help_content',
                        title: '培训内容',
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value && value.length > 30)
                                return "<span title='" + value + "'>" + value.substring(0, 30) + "...</span>";
                            return value;
                        }
                    }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //绑定默认事件
            bindEvent: function () {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
                //添加
                $('#trainAdd').click(function () {
                    helpTrainManager.editForm();
                });
                //编辑
                $('#trainEdit').click(function () {
                    var row = helpTrainManager.getSelect();
                    if (!row) {
                        layer.msg("未选中行~", { icon: 5 });
                        return false;
                    }
                    helpTrainManager.editForm(row);
                });
                //删除
                $('#trainDel').click(function () {
                    var row = helpTrainManager.getSelect();
                    if (!row) {
                        layer.msg("未选中记录行~", { icon: 5 });
                        return false;
                    }
                    layer.confirm('您确定要删除当前选中帮扶培训信息吗？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        var index = layer.msg("删除中...", { icon: 6, time: 6000 });
                        $.ajax({
                            type: 'post',
                            url: ctx + '/BaneJobIssue/delHelpTrainData/' + row.help_id,
                            dataType: 'json',
                            async: false,
                            success: function (data) {
                                if (index)
                                    layer.close(index);
                                if (data.Statu === 0) {
                                    isFrish = true;
                                    layer.msg("删除成功...");
                                    $table.bootstrapTable('refresh', options);
                                }
                                else
                                    layer.msg(data.Msg, { icon: 5 });
                            }
                        });
                    }, function () { });
                });
            },
            //获取选中行
            getSelect: function () {
                var row = $table.bootstrapTable('getSelections');
                if (row != null && row.length == 0) {
                    layer.msg("未选中行~", { icon: 5 });
                    return false;
                }
                return row[0];
            },
            //编辑、添加
            editForm: function (row) {
                var title = "添加帮扶培训信息";
                if (!row)
                    addOrEditUrl = ctx + "/BaneJobIssue/AddHelpTrainData";//新增
                else {
                    title = "编辑帮扶培训信息";
                    addOrEditUrl = ctx + "/BaneJobIssue/EditHelpTrainData";//编辑
                }
                //清空表单
                $('#orgFormTable').resetHideValidForm();
                //打开编辑
                layer.open({
                    title: [title, 'font-size:18px;'],
                    type: 1,
                    content: $('#org_form'),
                    scroll: true,//是否显示滚动条、默认不显示
                    btn: ['确定', '取消'],
                    area: ['550px', '500px'],
                    success: function (li, o) {
                        if (row != null) {
                            $('#orgFormTable')[0].reset();//重置表单
                            $('#orgFormTable').LoadForm(row);//表单填充数据
                        }
                    },
                    yes: function (li, o) {
                        if ($('#orgFormTable').valid()) {
                            //验证通过
                            $('#orgFormTable').ajaxSubmit({
                                url: addOrEditUrl,
                                type: "post",
                                dataType: "json",
                                beforeSubmit: function (arr, $form, options) {
                                    layer.msg("提交数据~", { icon: 1, time: 6000 });
                                },
                                success: function (result, status, xhr, $form) {
                                    isFrish = true;
                                    if (result.Statu === 0) {
                                        layer.closeAll();
                                        $table.bootstrapTable('refresh', options);
                                        layer.msg('保存成功', { icon: 1 });
                                    }
                                    else
                                        layer.alert(result.Msg, { icon: 5 });
                                },
                                error: function (xhr, status, error, $form) {
                                    layer.msg("保存失败~", { icon: 5 });
                                }
                            });
                        }
                    },
                    cancel: function (li, o) {

                    }
                });
            }
        }
    </script>
}

